package com.personal.system.controller.content;

import com.personal.common.result.Result;
import com.personal.system.entity.content.DictData;
import com.personal.system.service.content.DictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("/dictData")
@Api(tags = "字典数据管理")
@RequiredArgsConstructor
public class DictDataController {

    private final DictDataService dictDataService;

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ApiOperation(value = "字典数据列表", httpMethod = "GET", response = Result.class, notes = "字典数据列表")
    public Result list(Integer dictId, Integer isPublish){
        return dictDataService.listDictData(dictId,isPublish);
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ApiOperation(value = "添加字典数据", httpMethod = "POST", response = Result.class, notes = "添加字典数据")
    public Result insert(@RequestBody DictData dictData){
        return dictDataService.insertDictData(dictData);
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ApiOperation(value = "修改字典数据", httpMethod = "POST", response = Result.class, notes = "修改字典数据")
    public Result update(@RequestBody DictData dictData){
        return dictDataService.updateDictData(dictData);
    }

    @RequestMapping(value = "/delete",method = RequestMethod.DELETE)
    @ApiOperation(value = "删除字典数据", httpMethod = "DELETE", response = Result.class, notes = "删除字典数据")
    public Result deleteDictData(Long id){
        return dictDataService.deleteDictData(id);
    }

    @RequestMapping(value = "/deleteBatch",method = RequestMethod.DELETE)
    @ApiOperation(value = "批量删除字典数据", httpMethod = "DELETE", response = Result.class, notes = "批量删除字典数据")
    public Result deleteBatch(@RequestBody List<Long> ids){
        return dictDataService.deleteBatch(ids);
    }

    @RequestMapping(value = "/getDataByDictType",method = RequestMethod.POST)
    public Result getDataByDictType(@RequestBody List<String> types){
        return dictDataService.getDataByDictType(types);
    }
}

